
use std::fmt::Debug;
use std::io;
use std::num::{ParseIntError, ParseFloatError};
pub type Result<T> = std::result::Result<T, Error>;
/// A generic error that represents all the ways a method can fail inside of rexpr::core.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
    #[error("配置错误:{}", _0)]
    Conf(String),
    #[error("DB错误:{}", _0)]
    DataBase(String),
    #[error("{}", _0)]
    Other(String),
    #[error("{:?}", _0)]
    List(Vec<String>),
    #[error(transparent)]
    Anyhow(anyhow::Error),
}

impl From<io::Error> for Error {
    #[inline]
    fn from(err: io::Error) -> Self {
        Error::from(err.to_string())
    }
}
impl From<ParseIntError> for Error {
    #[inline]
    fn from(err: ParseIntError) -> Self {
        Error::Other(err.to_string())
    }
}
impl From<ParseFloatError> for Error {
    #[inline]
    fn from(err: ParseFloatError) -> Self {
        Error::Other(err.to_string())
    }
}
impl From<fancy_regex::Error> for Error {
    #[inline]
    fn from(err: fancy_regex::Error) -> Self {
        Error::Other(err.to_string())
    }
}
impl From<umya_spreadsheet::XlsxError> for Error {
    #[inline]
    fn from(err: umya_spreadsheet::XlsxError) -> Self {
        Error::Other(err.to_string())
    }
}
impl From<calamine::Error> for Error {
    #[inline]
    fn from(err: calamine::Error) -> Self {
        Error::Other(err.to_string())
    }
}
impl From<calamine::XlsxError> for Error {
    #[inline]
    fn from(err: calamine::XlsxError) -> Self {
        Error::Other(err.to_string())
    }
}
impl From<calamine::XlsError> for Error {
    #[inline]
    fn from(err: calamine::XlsError) -> Self {
        Error::Other(err.to_string())
    }
}
impl From<sqlx::Error> for Error {
    #[inline]
    fn from(err: sqlx::Error) -> Self {
        Error::DataBase(err.to_string())
    }
}
impl From<std::string::String> for Error {
    fn from(arg: String) -> Self {
        return Error::Other(arg);
    }
}
impl From<&str> for Error {
    fn from(arg: &str) -> Self {
        return Error::Other(arg.to_string());
    }
}
impl From<Error> for std::io::Error {
    fn from(arg: Error) -> Self {
        arg.into()
    }
}
impl From<serde_json::Error> for Error {
    fn from(arg: serde_json::Error) -> Self {
        Error::Other(arg.to_string())
    }
}
impl From<strum::ParseError> for Error {
    fn from(arg: strum::ParseError) -> Self {
        Error::Other(arg.to_string())
    }
}
impl From<serde_yaml::Error> for Error {
    fn from(arg: serde_yaml::Error) -> Self {
        Error::Conf(arg.to_string())
    }
}
impl From<anyhow::Error> for Error {
    fn from(arg: anyhow::Error) -> Self {
        Error::Anyhow(arg)
    }
}
impl Clone for Error {
    fn clone(&self) -> Self {
        Error::from(self.to_string())
    }

    fn clone_from(&mut self, source: &Self) {
        *self = Self::from(source.to_string());
    }
}
